import datetime
import calendar
import time
from datetime import date

calendar.setfirstweekday(calendar.SUNDAY)

today = date.today()

selected_day = today.day
selected_month = today.month
selected_year = today.year

def go_next_month():
    global selected_day
    global selected_month
    global selected_year
    selected_day = 1
    selected_month = selected_month+1
    if selected_month>12:
        selected_month = 1
        selected_year = selected_year+1

def go_prev_month():
    global selected_day
    global selected_month
    global selected_year
    selected_day = 1
    selected_month = selected_month-1
    if selected_month<1:
        selected_month=12
        selected_year = selected_year-1

def get_month_string(d):
    return d.strftime("%B %Y")

def get_this_month_string():
    dd = date(selected_year,selected_month,selected_day)
    return get_month_string(dd)

def get_box_number(row,col):
    try:
        return calendar.monthcalendar(selected_year, selected_month)[row][col]
    except:
        return 0

def get_box_label_rc(row,col):
    num = get_box_number(row,col)
    if num == 0:
        return ''
    else:
        return str(num)

def box_label_inverse(day_num):
    mc = calendar.monthcalendar(selected_year,selected_month)
    for i in range(6):
        for j in range(7):
            if mc[i][j] == day_num:
                return i,j

def get_box_label(i):
    row = i / 7
    col = i % 7
    return get_box_label_rc(row,col)




if __name__ == '__main__':
    print get_this_month_string()
    print get_box_label(0)
    print get_box_label(7)
    print get_box_label(8)
    print box_label_inverse(9)
    print calendar.monthcalendar(selected_year,selected_month)
